<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html {
            height: 5000px;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
            position: absolute;
            left: 50px;
            top: 50px;
        }
    </style>
</head>

<body>
    <div class="box">
    </div>
</body>
<script>
    // offsetLeft  offsetTop     返回元素相对于父代元素(参照物父元素)的偏移 (margin 和 定位)

    var box = document.getElementsByClassName("box")[0];
    console.log(box.offsetLeft, box.offsetTop);


</script>

</html>